package com.zhuss.idea.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.idea.idea.SearchIdeaBo;
import com.zhuss.bean.bo.idea.idea.wechat.ListIdeaBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.idea.idea.DetailIdeaVo;
import com.zhuss.bean.vo.idea.idea.ListIdeaVo;
import com.zhuss.idea.db.dao.ext.IdeaDao;
import com.zhuss.idea.db.entity.Idea;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询奇思妙想 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("ideaRead")
public class IdeaRead {
	
	@Autowired
	private IdeaDao ideaDao;
	
	/**
	 * 奇思妙想 
	 * @return
	 */
	public Object listIdeaId(Integer area) {
		List<Idea> ideaList = ideaDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(ideaList, result);
		return result;
	}
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = ideaDao.keyWord(bo);
		Integer count = ideaDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	
	/**
	 * 奇思妙想列表
	 * @param bo
	 * @return
	 */
	public Object listIdea(ListIdeaBo bo) {
		PageVo<DetailIdeaVo> result = new PageVo<DetailIdeaVo>();
		List<DetailIdeaVo> list = new ArrayList<DetailIdeaVo>();
		list = ideaDao.listIdea(bo);
		Integer count = ideaDao.countIdeaList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Idea> ideaList, List<Long> result) {
		for (Idea item : ideaList) {
			result.add(item.getIdeaId());
		}
	}

	/**
	 * 奇思妙想列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchIdeaBo bo) {
		PageVo<ListIdeaVo> result = new PageVo<ListIdeaVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(ideaDao.list(bo));
        result.setTotal(ideaDao.countList(bo));
		return result;
	}
	
	/**
	 * 奇思妙想详情
	 * @param ideaId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long ideaId) throws WpsException {
		Object result = ideaDao.detail(ideaId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
